<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/views/inc/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="decorator" content="main" />
<title>用户编辑</title>
<script type="text/javascript">
	var userPass = false;
	
	$(function() {
		$.extend($.fn.validatebox.defaults.rules, {
		 
		   
		    mobile: {
		        validator: function (value, param) {
		            return /^1[3|4|5|8][0-9]\d{4,8}$/.test(value);
		        },
		        message: '手机号码不正确'
		    }
		    
		  
		  
		 
		   
		});
		if ("${user.userid}" != "") {
			userPass = true;
		}
		$('#email').validatebox({
			required : true,
			validType : 'email'
			

		});
		$('#tel').validatebox({
			required : true,
			validType :  [ 'mobile','length[11,11]' ]

		});
		$('#status').validatebox({
			required : true,
			validType : 'length[0,100]'

		});
		$('#username').validatebox({
			required : true,
			validType : [ 'length[0,10]' ]

		});
		$('#psw').validatebox({
			required : true,
			validType :  'length[3,10]' 

		});
		$("#username").blur(
				function() {
					var context = $(this).val();
					if (context.trim() != "") {
						if (context.trim() != '${user.username}') {
							$.post("${ctx}/user/userInfo.do?method=findByName",
									{
										username : $('#username').val()
									}, function(data) {
										if (data == '1') {
											userPass = false;
											$("#validusername").text("该用户名已被占用")
													.css("color", "red");
										} else {
											$("#validusername").text("可以注册")
													.css("color", "green");
											userPass = true;
										}
									});
						} else {
							userPass = true;
						}
					} else {
						$("#validusername").text("不可以注册").css("color", "red");
					}
				});
	});
	function checkedsubmit() {
		/*  if($('input[name="username"]').val().trim()=="")
		 {
		 return false;  
		 }
		 if($('input[name="status"]').val().trim()=="")
		 {
		 return false;  
		 }
		 if($('input[name="tel"]').val().trim()=="")
		 {
		 return false;  
		 }
		 if($('input[name="email"]').val().trim()=="")
		 {
		 return false;  
		 }
		 if($('input[name="psw"]').val().trim()=="")
		 {
		 return false;  
		 } */

		if (!$('#status').validatebox("isValid")) {
			return false;
		}
		if (!$('#tel').validatebox("isValid")) {
			return false;
		}
		if (!$('#email').validatebox("isValid")) {
			return false;
		}
		if (!$('#psw').validatebox("isValid")) {
			return false;
		}

		if (!userPass) {
			return false;
		}
		return true;
	}
</script>
</head>
<body>
	<ul class="breadcrumbs">
		<li><a href="${ctx}/login/LoginIndexRequestServlet.do"><i
				class="iconfa-home"></i></a><span class="separator"></span></li>
		<li><a href="${ctx}/user/userInfo.do">用户管理</a> <span
			class="separator"></span></li>
		<li>${user.userid==0?'用戶添加':'用户编辑'}</li>
	</ul>

	<div class="maincontent">
		<div class="maincontentinner">
			<div class="row-fluid">
				<div class="span12">
					<div class="widget">
						<h4 class="widgettitle">${user.userid==0?'用戶添加':'用户编辑'}</h4>
						<div class="widgetcontent">
							<form onsubmit="return checkedsubmit()"
								action="${ctx}/user/userInfo.do" method="post">
								<input type="hidden" name="method"
									value="${user.userid==0?'insert':'update' }"> <input
									type="hidden" class="input-large" type="text" name="userid"
									value="${user.userid}"></input>
								<p style="padding-left: 260px">
									<label>用户名：</label> <input name="username" id="username"
										type="text" value=${user.userid==0?' ':user.username}><span
										id="validusername"></span>
								<p style="padding-left: 260px">
									<label>电话：</label> <input name="tel" id="tel" type="tel"
										value=${user.userid==0?' ':user.tel}>

								</p>
								<p style="padding-left: 260px">
									<label>用户描述：</label> <input name="status" id="status"
										type="text" value=${user.userid==0?' ':user.status}>

								</p>
								<p style="padding-left: 260px">
									<label>邮箱：</label> <input id="email" name="email" type="text"
										value=${user.userid==0?' ':user.email}>

								</p>
								<p style="padding-left: 260px">
									<label>密码：</label> <input id="psw" name="psw" type="password"
										value=${user.userid==0?' ':user.psw}>

								</p>


								<p style="padding-left: 260px">
									<input type="submit" value="提交" class="btn btn-primary">
									<input type="reset" class="btn" value="重置"></input>
								</p>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>